package com.ruoyi.web.controller.system;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.text.Convert;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CsceceeEmployee;
import com.ruoyi.system.service.ICsceceeEmployeeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中建电子人员库
 */
@RestController
@RequestMapping("/system/employee")
public class CsceceeEmployeeController extends BaseController
{
    @Autowired
    private ICsceceeEmployeeService csceceeEmployeeService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:employee:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsceceeEmployee csceceeEmployee)
    {
        startPage();
        List<CsceceeEmployee> list = csceceeEmployeeService.selectCsceceeEmployeeList(csceceeEmployee);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:employee:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsceceeEmployee csceceeEmployee)
    {
        List<CsceceeEmployee> list = csceceeEmployeeService.selectCsceceeEmployeeList(csceceeEmployee);
        ExcelUtil<CsceceeEmployee> util = new ExcelUtil<CsceceeEmployee>(CsceceeEmployee.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:employee:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(csceceeEmployeeService.selectCsceceeEmployeeById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:employee:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsceceeEmployee csceceeEmployee)
    {
        return toAjax(csceceeEmployeeService.insertCsceceeEmployee(csceceeEmployee));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:employee:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsceceeEmployee csceceeEmployee)
    {
        return toAjax(csceceeEmployeeService.updateCsceceeEmployee(csceceeEmployee));
    }


	@GetMapping("/updateFlag")
    public AjaxResult updateFlag( HttpServletRequest req)
    {
        String flag = req.getParameter("flag");
        String idsStr = req.getParameter("ids");
        String[]ids = idsStr.split(",");
        Arrays.asList(ids).forEach(id -> {
            CsceceeEmployee entity = this.csceceeEmployeeService.selectCsceceeEmployeeById(Convert.toLong(id));
            entity.setUpdateTime(new Date());
            entity.setLdFlag(Convert.toInt(flag));
            this.csceceeEmployeeService.updateCsceceeEmployee(entity);
        });
        return AjaxResult.success();
    }

	@GetMapping("/updateFlag1")
    public AjaxResult updateFlag1( Long[]ids,Integer flag)
    {
        Arrays.asList(ids).forEach(id -> {
            CsceceeEmployee entity = this.csceceeEmployeeService.selectCsceceeEmployeeById(Convert.toLong(id));
            entity.setUpdateTime(new Date());
            entity.setLdFlag(Convert.toInt(flag));
            this.csceceeEmployeeService.updateCsceceeEmployee(entity);
        });
        return AjaxResult.success();
    }
}
